﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using ICSharpCode.SharpZipLib.Zip;
using DesktopDOHS.appData.Schemas;
using System.Net;

namespace PocketDOHS
{
    public partial class TransDados : Form
    {
        public TransDados()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            ZipFile zip = ZipFile.Create(@"C:\DesktopDOHS\msgDOHS" + DateTime.Now.ToString("dd_MM_yyyy") + ".omsz");
            TextReader trPDA = new StreamReader(@"\Program Files\DesktopDOHS\Mensagens\MsgDOHSLog.oms");
            XmlSerializer xs = new XmlSerializer(typeof(MensagemDOHS));
            MensagemDOHS msgDOHSLogPDA = (MensagemDOHS)xs.Deserialize(trPDA);
            trPDA.Close();
            zip.BeginUpdate();
            zip.Add(@"\Program Files\DesktopDOHS\Mensagens\MsgDOHSLog.oms");
            if (msgDOHSLogPDA.ExamesDOHS != null)
            {
                int indice = msgDOHSLogPDA.ExamesDOHS.Count();
                for (int i = 0; i < indice; i++)
                    zip.Add(@"\Program Files\DesktopDOHS\Mensagens\" + ((MensagemDOHSExamesDOHSMsgLog)msgDOHSLogPDA.ExamesDOHS[i].Item).Path);
            }
            zip.CommitUpdate();
            zip.Close();

            if (MessageBox.Show("Deseja Limpar os Registros do PDA?",
                                "Atenção!", MessageBoxButtons.YesNo,
                                MessageBoxIcon.Question,
                                MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                File.Copy("\\Program Files\\DesktopDOHS\\Resources\\MsgDOHSLog.oms", "\\Program Files\\DesktopDOHS\\Mensagens\\MsgDOHSLog.oms", true);
            this.Close();
        }
    }
}